package util;

import java.io.File;

import javax.swing.filechooser.FileFilter;

/**
 * Used to filter files in a JFileChooser dialog.
 * @author TKington
 *
 */
public class SimpleFileFilter extends FileFilter {
	/** Filter description. */
    private String desc;
    /** Filter extension. */
    private String ext;
    
    /**
     * Creates a new SimpleFileFilter.
     * @param desc The description of the file type, e.g. "SGF Files"
     * @param ext The extension we're looking for, e.g. "sgf"
     */
    public SimpleFileFilter(String desc, String ext) {
        this.desc = desc;
        this.ext = ext;
    }
    
    @Override
	public String getDescription() { return desc; }
    
    /**
     * @return The file extension that will be displayed by the filter, e.g. "sgf"
     */
    public String getExt() { return ext; }
    
    @Override
	public boolean accept(File f) {
        if(f.isDirectory()) return true;
        return f.getName().toLowerCase().endsWith(ext);
    }
}